import React from 'react';
import PropTypes from 'prop-types';
import {Button} from 'antd';
import {formatMessage} from './intl';
export const ImagePreviewBtn = ({attachments}) => {
    if(attachments && attachments.length > 0) {
        const imageReg = new RegExp(/\.(gif|png|jpg|jpeg)$/i);
        const images = attachments.filter(file =>
            imageReg.test(file.fileName)
        );
        const queryString = images
            .map(file => `fileList=${file.fileId}:${file.fileName}`)
            .join('&');
        const url = `#dcs/afterSales/imagePreview?${queryString}`;
        return (
            // eslint-disable-next-line react/react-in-jsx-scope
            <Button size="small" href={url} target="_blank">
                {formatMessage({
                    id: 'btn.imagePreview',
                    defaultMessage: '图片预览'
                })}
            </Button>
        );
    }
    return null;
};
ImagePreviewBtn.propTypes = {
    attachments: PropTypes.array,
};
export default ImagePreviewBtn;
